home *** CD-ROM | disk | FTP | other *** search
/ Software of the Month Club (Business) 1997 July / Software of the Month Club - Business (Volume 239) (July 1997).iso / pc / code / shared.dxr / 04467_Initialize XOBJS.ls < prev    next >
Encoding:
Text File  |  1996-02-21  |  8.6 KB  |  270 lines

  1. global gObjectsA, gObjectsB, gObjectsC, gObjectsD, gObjectsE, gObjectsF, gObjectsG, gObjectsH, gWorld, gStates, gOBJECTS, void, gFixPalette, miscXobj, gInitalized, noav, gNextEnvLetter, gNextDIRFile, gMIDIPlayTRUE, noteObjs, windowsMIDIXObj, xNAVXOBJ, xCURXOBJ, gCPU, gfileSep, gRootPath, gHDpath, gXobjs, gXOBJPath, gCDpath, gCDName, gInstrumentScale, sPALETTE, HARP, TIGO, HORN, DRUM, CHIME, BASS, wholeToneScale, harmonicMinorScale, majorScale, bluesScale, gScales, gMIDIINTERRUPTFREQUENCY, gMIDIINTERRUPTDURATION, gNotes, gMidiManager, gCDNotes, outDevNumsList, myMidiDevice, gLimitPreLoad
  2.  
  3. on InitXOBJs
  4.   if listp(gXobjs) then
  5.     exit
  6.   end if
  7.   InitalizePaths()
  8.   OpenChaosXlibs()
  9.   if not noav then
  10.     set xMIDI to OpenMIDIXOBJ()
  11.   end if
  12.   if gCPU = #MAC then
  13.     set gFixPalette to FixPalette(mnew, the stageLeft, the stageTop, the stageRight, the stageBottom)
  14.   end if
  15.   set xNAVXOBJ to OffScreen(mnew, string(gCDName & "CODE" & gfileSep & "NAV.BMP"), 0, 0, 4)
  16.   set gXobjs to [#MIDI: xMIDI, #NAV: xNAVXOBJ]
  17. end
  18.  
  19. on CloseUniversalXOBJs
  20.   if not noav then
  21.     CLOSEMIDIXOBJ()
  22.   end if
  23.   if objectp(xNAVXOBJ) then
  24.     xNAVXOBJ(mdispose)
  25.   end if
  26.   if objectp(xCURXOBJ) then
  27.     xCURXOBJ(mdispose)
  28.   end if
  29.   if objectp(gFixPalette) then
  30.     gFixPalette(mdispose)
  31.   end if
  32.   if objectp(miscXobj) then
  33.     miscXobj(mdispose)
  34.   end if
  35.   openXLib(string(gXOBJPath & "MovieUtilities XObj"))
  36.   CLOSEChaosXlibs()
  37.   set gXobjs to void
  38. end
  39.  
  40. on InitalizePaths
  41.   if the machineType = 256 then
  42.     set gfileSep to "\"
  43.     if voidp(gHDpath) then
  44.       set gHDpath to "C:\chaos\"
  45.     end if
  46.     if voidp(gCDpath) then
  47.       set gCDpath to "D:\"
  48.     end if
  49.     set gCDName to gCDpath
  50.     set gXOBJPath to gCDName & "XOBJs\"
  51.   else
  52.     set gCPU to #MAC
  53.     set gfileSep to ":"
  54.     set gHDpath to the pathName
  55.     set gCDName to "Chaos:"
  56.     set gXOBJPath to gCDName & "XOBJMAC:"
  57.   end if
  58. end
  59.  
  60. on OpenChaosXlibs
  61.   if gCPU = #mpc then
  62.     openXLib(string(gHDpath & "FILEIO.DLL"))
  63.     openXLib(string(gXOBJPath & "MovUtils.DLL"))
  64.     openXLib(string(gXOBJPath & "MISC_X.DLL"))
  65.     openXLib(string(gXOBJPath & "OFFSCRN.DLL"))
  66.     openXLib(string(gXOBJPath & "MIDIXOBJ.DLL"))
  67.   else
  68.     if gCPU = #MAC then
  69.       openXLib(string(gXOBJPath & "FixPalette XObj"))
  70.       openXLib(string(gXOBJPath & "MovieUtilities XObj"))
  71.       openXLib(string(gXOBJPath & "Misc_X XObj"))
  72.       openXLib(string(gXOBJPath & "OffScreenXOBJ"))
  73.       if not noav then
  74.         openXLib(string(gXOBJPath & "PlayNote.Xobj"))
  75.       end if
  76.     end if
  77.   end if
  78. end
  79.  
  80. on CLOSEChaosXlibs
  81.   if gCPU = #mpc then
  82.     closeXLib(string(gHDpath & "FILEIO.DLL"))
  83.     closeXLib(string(gXOBJPath & "MovUtils.DLL"))
  84.     closeXLib(string(gXOBJPath & "MISC_X.DLL"))
  85.     closeXLib(string(gXOBJPath & "OFFSCRN.DLL"))
  86.     closeXLib(string(gXOBJPath & "MIDIXOBJ.DLL"))
  87.   else
  88.     if gCPU = #MAC then
  89.       closeXLib(string(gXOBJPath & "FixPalette XObj"))
  90.       closeXLib(string(gXOBJPath & "MovieUtilities XObj"))
  91.       closeXLib(string(gXOBJPath & "Misc_X XObj"))
  92.       closeXLib(string(gXOBJPath & "OffScreenXOBJ"))
  93.       if not noav then
  94.         closeXLib(string(gXOBJPath & "PlayNote.Xobj"))
  95.       end if
  96.     end if
  97.   end if
  98. end
  99.  
  100. on writeWindowsMIDIProgramChange instrument, progNum
  101.   set str to string(192 + instrument - 1 && progNum)
  102.   windowsMIDIXObj(mWrite, str)
  103. end
  104.  
  105. on closeMIDIXObjOut
  106.   if gCPU = #mpc then
  107.     if objectp(windowsMIDIXObj) then
  108.       windowsMIDIXObj(mCloseOut)
  109.     end if
  110.   end if
  111. end
  112.  
  113. on openMIDIXObjOut
  114.   if gCPU = #mpc then
  115.     if objectp(windowsMIDIXObj) then
  116.       windowsMIDIXObj(mCloseOut)
  117.     else
  118.       abort()
  119.     end if
  120.     if count(outDevNumsList) > 0 then
  121.       set outDevID to getAt(outDevNumsList, myMidiDevice)
  122.       if windowsMIDIXObj(mOpenOut, outDevID, 1024) then
  123.         beep()
  124.         alert("The selected device appears to be busy by another application. Please quit all other applications and restart game.")
  125.         abort()
  126.       end if
  127.     else
  128.       abort()
  129.     end if
  130.     writeWindowsMIDIProgramChange(HARP, 8)
  131.     writeWindowsMIDIProgramChange(TIGO, 14)
  132.     writeWindowsMIDIProgramChange(HORN, 66)
  133.     writeWindowsMIDIProgramChange(DRUM, 115)
  134.     writeWindowsMIDIProgramChange(CHIME, 99)
  135.     writeWindowsMIDIProgramChange(BASS, 37)
  136.   end if
  137. end
  138.  
  139. on OpenMIDIXOBJ
  140.   initScalesMixxer()
  141.   if gCPU = #mpc then
  142.     if objectp(windowsMIDIXObj) then
  143.       CLOSEMIDIXOBJ()
  144.     end if
  145.     set windowsMIDIXObj to midixobj(mnew)
  146.     if not objectp(windowsMIDIXObj) then
  147.       go("warning", "Intro")
  148.       alert("Could not find Midi.dll")
  149.     end if
  150.     set devNumsList to value(windowsMIDIXObj(mGetDevIDs))
  151.     set outDevNumsList to getAt(devNumsList, 2)
  152.     if count(outDevNumsList) > 0 then
  153.       if loadPrefData() then
  154.       else
  155.         set myMidiDevice to 1
  156.         set gLimitPreLoad to 0
  157.       end if
  158.       set outDevID to getAt(outDevNumsList, myMidiDevice)
  159.       if windowsMIDIXObj(mOpenOut, outDevID, 1024) then
  160.         beep()
  161.         go("warning", "Intro")
  162.         alert("The selected device appears to be busy by another application. Please quit all other applications and restart game.")
  163.         abort()
  164.       end if
  165.     else
  166.       go("warning", "Intro")
  167.       abort()
  168.     end if
  169.     writeWindowsMIDIProgramChange(HARP, 8)
  170.     writeWindowsMIDIProgramChange(TIGO, 14)
  171.     writeWindowsMIDIProgramChange(HORN, 66)
  172.     writeWindowsMIDIProgramChange(DRUM, 115)
  173.     writeWindowsMIDIProgramChange(CHIME, 99)
  174.     writeWindowsMIDIProgramChange(BASS, 37)
  175.     set midiObj to windowsMIDIXObj
  176.   else
  177.     if listp(noteObjs) then
  178.       CLOSEMIDIXOBJ()
  179.     end if
  180.     set noteObjs to []
  181.     add(noteObjs, playNote(mnew, 8, 2, 1, 0))
  182.     add(noteObjs, playNote(mnew, 14, 2, 1, 0))
  183.     add(noteObjs, playNote(mnew, 66, 2, 1, 0))
  184.     add(noteObjs, playNote(mnew, 115, 2, 1, 0))
  185.     add(noteObjs, playNote(mnew, 99, 2, 1, 0))
  186.     add(noteObjs, playNote(mnew, 37, 2, 1, 0))
  187.     set midiObj to noteObjs
  188.   end if
  189.   set gCDNotes to [#HARP: [], #Timur: [], #HORN: [], #DRUM: [], #CHIME: [], #BASS: []]
  190.   InitMidiGlobals()
  191.   return midiObj
  192. end
  193.  
  194. on InitMidiGlobals
  195.   set gNotes to [#HARP: [], #Timur: [], #HORN: [], #DRUM: [], #CHIME: [], #BASS: []]
  196.   set gMidiManager to [#HARP: [#Pointer: -1, #note: 0, #velocity: 127, #Channel: 1, #Start: -1, #stop: 0], #Timur: [#Pointer: -1, #note: 0, #velocity: 127, #Channel: 2, #Start: -1, #stop: 0], #HORN: [#Pointer: -1, #note: 0, #velocity: 127, #Channel: 3, #Start: -1, #stop: 0], #DRUM: [#Pointer: -1, #note: 0, #velocity: 127, #Channel: 4, #Start: -1, #stop: 0], #CHIME: [#Pointer: -1, #note: 0, #velocity: 127, #Channel: 5, #Start: -1, #stop: 0], #BASS: [#Pointer: -1, #note: 0, #velocity: 127, #Channel: 6, #Start: -1, #stop: 0]]
  197. end
  198.  
  199. on CLOSEMIDIXOBJ
  200.   if gCPU = #mpc then
  201.     if objectp(windowsMIDIXObj) then
  202.       windowsMIDIXObj(mCloseOut)
  203.       windowsMIDIXObj(mdispose)
  204.       set windowsMIDIXObj to EMPTY
  205.     end if
  206.   else
  207.     repeat with ix = 1 to 6
  208.       set obj to getAt(noteObjs, ix)
  209.       if objectp(obj) then
  210.         set objectsExist to 1
  211.         obj(mDisposePrep)
  212.         obj(mdispose)
  213.       end if
  214.       setAt(noteObjs, ix, EMPTY)
  215.     end repeat
  216.     set noteObjs to EMPTY
  217.   end if
  218. end
  219.  
  220. on initScalesMixxer
  221.   set HARP to 1
  222.   set TIGO to 2
  223.   set HORN to 3
  224.   set DRUM to 4
  225.   set CHIME to 5
  226.   set BASS to 6
  227.   set wholeToneScale to list(1, 3, 5, 7, 9, 11)
  228.   set harmonicMinorScale to list(1, 3, 4, 6, 8, 9, 11)
  229.   set majorScale to list(1, 3, 5, 6, 8, 10, 11)
  230.   set bluesScale to list(1, 4, 6, 8, 10)
  231.   set gScales to [wholeToneScale, harmonicMinorScale, majorScale, bluesScale]
  232.   set gInstrumentScale to [1, 2, 3, 4, 1, 2]
  233. end
  234.  
  235. on setPaletteAndScale instrumentNum, selection, obj
  236.   set cnum to getaProp(getaProp(obj, #cast), string(selection))
  237.   set spriteNum to getaProp(obj, #spriteNum)
  238.   set the castNum of sprite spriteNum to cnum
  239.   setaProp(obj, #DisplayState, string(selection))
  240.   updateStage()
  241.   setAt(gInstrumentScale, instrumentNum, selection)
  242. end
  243.  
  244. on getRandomNote instrument, loOctave, hiOctave
  245.   set scale to getAt(gScales, getAt(gInstrumentScale, instrument))
  246.   set noteNum to getAt(scale, random(count(scale))) - 1
  247.   set octaveNum to random(hiOctave - loOctave + 1) - 1
  248.   return (12 * (octaveNum + loOctave)) + noteNum
  249. end
  250.  
  251. on constrainHalfToneToScale instrument, halfTone
  252.   set scale to getAt(gScales, getAt(gInstrumentScale, instrument))
  253.   set numIntervals to count(scale)
  254.   repeat with interval = 1 to numIntervals
  255.     set theValue to getAt(scale, interval)
  256.     if theValue >= halfTone then
  257.       return theValue
  258.     end if
  259.   end repeat
  260.   return getAt(scale, numIntervals)
  261. end
  262.  
  263. on indexedNoteInInstrumentScale instrument, index
  264.   set scale to getAt(gScales, getAt(gInstrumentScale, instrument))
  265.   set maxIndex to count(scale)
  266.   set octave to index / (maxIndex + 1)
  267.   set index to ((index - 1) mod maxIndex) + 1
  268.   return getAt(scale, index) + (12 * octave)
  269. end
  270.